package com.example.yuejianapp14.Activity.Activity;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.example.yuejianapp14.Activity.JavaBean.Act;
import com.example.yuejianapp14.Activity.JavaBean.Game;
import com.example.yuejianapp14.Activity.JavaBean.Success;
import com.example.yuejianapp14.Activity.Listener.ClubNoListListener;
import com.example.yuejianapp14.Activity.Listener.ListListener;
import com.example.yuejianapp14.Activity.Model.ActivityModel;
import com.example.yuejianapp14.Activity.Model.EnterModel;
import com.example.yuejianapp14.Activity.Model.GameModel;
import com.example.yuejianapp14.R;
import com.squareup.picasso.Picasso;

public class GameActivity extends AppCompatActivity {
      private TextView gamename,gamelink;
      private ImageView gamepic;
      private Button gameup;
    private Context mContext;
    private SharedPreferences sp;
    String etype;
    String etypeid;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_game);
        initViews();
        getData();
        gamebtn();
        Intent intent=getIntent();
        intent.getStringExtra("gameid");
        etypeid= intent.getStringExtra("gameid");
        Picasso.with(mContext).load("http://10.0.2.2/YueJian/Public/photo/competition/"+getIntent().getStringExtra("gamepic")).into(gamepic);

    }
    public void initViews(){
        gamelink=(TextView) findViewById(R.id.gamelink);
        gamename=(TextView) findViewById(R.id.gamename);
        gamepic=(ImageView) findViewById(R.id.gamepic);
        gameup=(Button) findViewById(R.id.gameup);
        sp=getSharedPreferences("uid",MODE_PRIVATE);

    }


    ClubNoListListener<Game> clubNoListListener =new ClubNoListListener<Game>() {
        @Override
        public void onResponse(Game game) {
            gamelink.setText(game.getLink());
            gamename.setText(game.getCompetition());
        }

        @Override
        public void onFail(String msg) {

        }
    };

    private void getData() {
        Intent intent = getIntent();
        GameModel gameModel =new GameModel();
        gameModel.gameinfo(intent.getStringExtra("gameid"),clubNoListListener);
    }

    private void gamebtn(){
        gameup.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                EnterModel enterModel =new EnterModel();
                enterModel.enter(sp.getString("uid",""),"3",etypeid, EnterListener);
            }
        });
    }

    ListListener<Success> EnterListener=new ListListener<Success>() {
        @Override
        public void onResponse(Success a) {
            if (a.getSuccess().equals("1")) {
                Toast.makeText(GameActivity.this, "报名成功", Toast.LENGTH_SHORT).show();
            }
        }

        @Override
        public void onFail(String msg) {
                Toast.makeText(GameActivity.this, "报名失败", Toast.LENGTH_SHORT).show();
        }
    };





}
